Option Public
Option Declare


Sub Initialize
	'比较两个数据库中文档
	'Copyright Botstation (www.botstation.com) 
	Dim session As New NotesSession 
	Dim db1 As NotesDatabase
	Dim db2 As NotesDatabase
	Dim coll As NotesDocumentCollection
	Dim doc As NotesDocument
	'We use List data type for holding values. This is done to achieve faster performance when comparing values from 2 databases. 
	Dim db1list List As String 'List1 
	Dim db2list List As String 'List2
	Dim x As Integer
	Dim y As Integer

	Set db1=New NotesDatabase("Server1", "names.nsf" ) 
	Set db2=New NotesDatabase("Server2", "names.nsf" ) 

	'Get a collection of documents 
	Set coll=db1.search(|Form="Group"|, Nothing, 0) 'db1.AllDocuments
	Set doc=coll.getfirstdocument
	While Not doc Is Nothing
		'populate List1 with values from documents
		db1list(doc.universalid)=doc.universalid 
		Set doc=coll.getnextdocument(doc)
		x=x+1
	Wend

	'Get a collection of documents 
	Set coll=db2.search(|Form="Group"|, Nothing, 0) 'db2.AllDocuments
	Set doc=coll.getfirstdocument
	While Not doc Is Nothing
		'populate List2 with values from documents 
		db2list(doc.universalid)=doc.universalid 'Cstr(doc.created)
		Set doc=coll.getnextdocument(doc)
		y=y+1
	Wend

	'Find out what documents are missing in db2 by coparing all values in List1 with values in List2 
	ForAll v In db1list
		If Not IsElement ( db2list ( ListTag(v) ) ) Then
			Print ListTag(v)+" is missing in db2"
		End If
	End ForAll

	'Find out what documents are missing in db1 by coparing all values in List2 with values in List1 
	ForAll v In db2list
		If Not IsElement ( db1list ( ListTag(v) ) ) Then
			Print ListTag(v)+" is missing in db1"
		End If
	End ForAll

	Print "Done"
End Sub
